import QtQuick 2.12
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import SerialPort 1.0

Rectangle {
    id: root
    height: 400
    width: 600
    property bool use: true

    ListModel{
        id:logModel
    }

    Component.onCompleted: {

    }

    function addLog( msg) {
        logModel.append({
                            "msg": msg
                        })

        if (logModel.count > 105) {
            logModel.remove(0, 5)
        }

    }

    function clear(){
        logModel.clear()
    }

    Component {
        id: listDelegate
        Rectangle {
            id: content
            anchors {
                left: parent.left
                right: parent.right
            }
            height: column.implicitHeight + 10
//            border.width: 1
//            border.color: "lightsteelblue"
            radius: 2
            Column {
                id: column
                Text {
                    width: content.width
                    text:  msg
                    wrapMode: Text.WrapAnywhere
                }
            }
        }
    }
    ScrollView {
        id: scrollView
        anchors.fill: parent
        visible: true


        ListView {
            id: listview
            highlight: Rectangle {
                color: "lightsteelblue"
                radius: 5
            }
            focus: true
            anchors {
                fill: parent
                margins: 2
            }
            model: logModel
            delegate: listDelegate
            spacing: 4
            cacheBuffer: 50
        }
    }
}
